package com.hu.hutool.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.commons.tools.page.PageData;
import com.commons.tools.utils.ConvertUtils;
import com.hu.hutool.dao.UserDao;
import com.hu.hutool.dto.UserDto;
import com.hu.hutool.dto.vo.UserVo;
import com.hu.hutool.entity.User;
import com.hu.hutool.service.IUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author CazCen
 * @Date 2021/11/3 14:46
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserDao, User> implements IUserService {

    @Resource
    UserDao userDAO;

    @Override
    public PageData<UserDto> getUserList(UserVo vo) {

//        Assert.isNull(vo.getPhone());

        Page<User> page = new Page(vo.getPageIndex(), vo.getPageSize());

        List<User> allUser = userDAO.getAllUser(vo, page);

        List<UserDto> convert = ConvertUtils.convert(allUser, UserDto.class);

        return new PageData(convert, page.getTotal());
    }

    @Override
    public UserDto getOneUser(UserVo vo) {
        User oneUser = userDAO.getOneUser(vo);
        UserDto convert = ConvertUtils.convert(oneUser, UserDto.class);
        return convert;
    }
}
